/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.coopeud.vista.eventos;

import edu.coopeud.persistencia.dao.EventoDao;
import edu.coopeud.persistencia.model.Evento;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Alejo
 */
public class VentanaCrearEvento extends javax.swing.JFrame {

    private VentanaEventos ventana;
    
    public VentanaCrearEvento() {
        super("Crear Evento");
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblUno = new javax.swing.JLabel();
        txtNombreEvt = new javax.swing.JTextField();
        lblDos = new javax.swing.JLabel();
        lblTres = new javax.swing.JLabel();
        txtFinEvt = new javax.swing.JTextField();
        txtInicioEvt = new javax.swing.JTextField();
        txtFechaMaxInscEvt = new javax.swing.JTextField();
        lblCuatro = new javax.swing.JLabel();
        lblCinco = new javax.swing.JLabel();
        txtValorEvt = new javax.swing.JTextField();
        txtMaxInscEvt = new javax.swing.JTextField();
        lbSeis = new javax.swing.JLabel();
        lblSiete = new javax.swing.JLabel();
        cbxCampoJuego = new javax.swing.JComboBox();
        btnCrearEvt = new javax.swing.JButton();
        lblDiez = new javax.swing.JLabel();
        cbxCopago = new javax.swing.JCheckBox();
        lblOnce = new javax.swing.JLabel();
        cbxProveedor = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        lblUno.setText("Nombre del Evento");

        lblDos.setText("Fecha de Inicio");

        lblTres.setText("Fecha de Finalización");

        lblCuatro.setText("Fecha Máxima de Inscripción");

        lblCinco.setText("Precio Total del Evento");

        lbSeis.setText("Máximo Número de Inscripciones");

        lblSiete.setText("Tipo de Evento");

        cbxCampoJuego.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Académico", "Cultural", "Deportivo", "Recreativo" }));

        btnCrearEvt.setText("Crear");
        btnCrearEvt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCrearEvtActionPerformed(evt);
            }
        });

        lblDiez.setText("¿Tiene Copago?");

        cbxCopago.setText("Con Copago");

        lblOnce.setText("Seleccione Proveedor");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(lblOnce, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblDiez, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblUno, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblTres, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblDos, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblCuatro, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lblCinco, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(lbSeis, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 181, Short.MAX_VALUE)
                            .addComponent(lblSiete, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(cbxCampoJuego, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtNombreEvt)
                            .addComponent(txtInicioEvt)
                            .addComponent(txtFinEvt)
                            .addComponent(txtFechaMaxInscEvt)
                            .addComponent(txtValorEvt)
                            .addComponent(txtMaxInscEvt)
                            .addComponent(cbxCopago, javax.swing.GroupLayout.DEFAULT_SIZE, 141, Short.MAX_VALUE)
                            .addComponent(cbxProveedor, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(140, 140, 140)
                        .addComponent(btnCrearEvt)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(lblUno)
                    .addComponent(txtNombreEvt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtInicioEvt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDos))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtFinEvt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblTres))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtFechaMaxInscEvt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCuatro))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtValorEvt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCinco))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbSeis)
                    .addComponent(txtMaxInscEvt, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblOnce)
                    .addComponent(cbxProveedor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblSiete)
                    .addComponent(cbxCampoJuego, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbxCopago)
                    .addComponent(lblDiez))
                .addGap(18, 18, 18)
                .addComponent(btnCrearEvt)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCrearEvtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCrearEvtActionPerformed
        
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        
        EventoDao eventoDao = EventoDao.getInstanciaEventoDao();
        
        Evento evento = new Evento();
        
        evento.setnNombreEvento(this.txtNombreEvt.getText());
        //evento.setiTipoEvento(cbxCampoJuego.getSelectedItem().toString());
        evento.setiTipoEvento(cbxCampoJuego.getSelectedItem().toString());
        
        try {
            evento.setfInicio(dateFormat.parse(this.txtInicioEvt.getText()));
            evento.setfFin(dateFormat.parse(this.txtFinEvt.getText()));
            evento.setfMaxInscripcion(dateFormat.parse(this.txtFechaMaxInscEvt.getText()));
        } catch (ParseException ex) {
            Logger.getLogger(VentanaCrearEvento.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        //VALOR QUEMADO
        evento.setFkNitProveedor(2);
        
        evento.setvMaxParticipantes(new Integer(this.txtMaxInscEvt.getText()).intValue());
        evento.setvValorEvento(new Integer(this.txtValorEvt.getText()).intValue());
        evento.setvValorCopago(1);
        evento.setiEstadoEvento("Abierto");
        evento.setoObservaciones("ninguna");
                               
        int respuesta = eventoDao.crearEvento(evento);
        
        System.out.println("crearEvento: "+respuesta);
    }//GEN-LAST:event_btnCrearEvtActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        cerrar();
        getVentana().setVisible(true);
    }//GEN-LAST:event_formWindowClosing

    public void cerrar(){
        dispose();
    }
    
    public VentanaEventos getVentana(){
        if (ventana==null){
            ventana=new VentanaEventos();
        }
        return ventana;
    }
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCrearEvt;
    private javax.swing.JComboBox cbxCampoJuego;
    private javax.swing.JCheckBox cbxCopago;
    private javax.swing.JComboBox cbxProveedor;
    private javax.swing.JLabel lbSeis;
    private javax.swing.JLabel lblCinco;
    private javax.swing.JLabel lblCuatro;
    private javax.swing.JLabel lblDiez;
    private javax.swing.JLabel lblDos;
    private javax.swing.JLabel lblOnce;
    private javax.swing.JLabel lblSiete;
    private javax.swing.JLabel lblTres;
    private javax.swing.JLabel lblUno;
    private javax.swing.JTextField txtFechaMaxInscEvt;
    private javax.swing.JTextField txtFinEvt;
    private javax.swing.JTextField txtInicioEvt;
    private javax.swing.JTextField txtMaxInscEvt;
    private javax.swing.JTextField txtNombreEvt;
    private javax.swing.JTextField txtValorEvt;
    // End of variables declaration//GEN-END:variables
}
